package com.homedo.odin.solution.enumcode.other;

import java.util.Arrays;
import lombok.Getter;

/**
 * VIP会员等级
 *
 * @author zhanglei
 */
@Getter
public enum MemberLevelEnum {
    VIP_LEVEL_1(1, "VIP1"),
    VIP_LEVEL_2(2, "VIP2"),
    VIP_LEVEL_3(3, "VIP3"),
    VIP_LEVEL_4(4, "VIP4"),
    VIP_LEVEL_5(5, "VIP5"),
    VIP_LEVEL_6(6, "VIP6");

    private Integer dbValue;
    private String displayValue;

    MemberLevelEnum(Integer dbValue, String displayValue) {
        this.displayValue = displayValue;
        this.dbValue = dbValue;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(MemberLevelEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(MemberLevelEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }


    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(MemberLevelEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }
}
